function sumbit_review(pid, rid, aid) {
    var name = $("#name").val(),
        email = $("#email").val(),
        phone = $("#phone").val(),
        content = $("#content").val();

    if (isNull(name) || isNull(email) || isNull(content)) {
        alert("名称, 邮箱, 留言内容不可为空");
        return false;
    }

    var p_data = {
        'name': name
    };
    p_data['email'] = email;
    p_data['phone'] = phone;
    p_data['content'] = content;
    p_data['pid'] = pid;
    p_data['rid'] = rid;
    p_data['aid'] = aid;

    $.post('', p_data, function (data) {
        if (data.code == 2) {
            console.log(data.data)
            var message = data.data;

            var li_html = '<li  class="li_box">';
                
            li_html += '<div class="p_author">' + message.name + '</div>';
            
            li_html += '<div class="content_box">';

            li_html += '<div class="p_content_box">' 
                + '<div id="p_content_' + message.id + '" class="p_content">' 
                + message.content + '</div>';

            li_html += '<div class="p_botton">'
                + '<a href="#" class=""><span class="lzl_link_fold">收起回复</span></a>&nbsp;|&nbsp;'
                + '<a href="#" class="tail-info" data-checkun="un"><span class="j_jb_ele">举报</span></a>&nbsp;|&nbsp;' 
                + '<span class="tail-info">' + message.time + '</span></div></div>';
            
            li_html += '<div class="active_replay"><div class="replay_button">'
                + '<a href="javascript:void(0)" class="btn btn-defalut" '
                + 'onclick="show_form(this, '+message.id+', 0, 0)">我也说一句</a></div></div>';

            li_html += '</div>';

            li_html += '</li>';

            $(".ul_box").prepend(li_html);
        } else {
            alert('添加出错');
            return false;
        }
    }, 'json');

    return false;
}

function show_form(obj, pid, rid, aid) {
    $('.replay_textarea').remove();
    $('.replay_button').css('display', 'block');
    var form_html = '<div class="replay_textarea"><form action="" method="POST">';
    form_html += '<div class="input_text"><span style="color: red;">*</span><input type="text" class="r_name" name="name" placeholder="Your Name" autocomplete="name">'
        + '<span style="color: red;">*</span><input type="text" class="r_email" name="email" placeholder="Your email" autocomplete="email">'
        + '<input type="text" class="r_phone" name="phone" placeholder="Your phone" autocomplete="phone"></div>'
        + '<textarea class="r_content" name="content" placeholder="200个字符以内" onKeyUp="textarealength(this,200)"></textarea>'
        + '<p><em class="text_num">0</em>/200</p>';
    form_html += '<input type="hidden" name="pid" value="'+pid+'">';
    form_html += '<input type="hidden" name="rid" value="'+rid+'">';
    form_html += '<input type="hidden" name="aid" value="'+aid+'">';
    form_html += '<input type="button" onClick="add_review(this)" value="确定">';
    form_html += '<input type="button" onClick="cancel_review(this)" value="取消" style="background-color:#F83707">';
    form_html += '</form></div>';
    // console.log(form_html);
    $(obj).parent('div').after(form_html);
    $(obj).parent('div').css('display', 'none');
}

function cancel_review(obj) {
    $(obj).parents('.replay_textarea').prev('.replay_button').css('display', 'block');
    $(obj).parents('.replay_textarea').remove();
}

function add_review(obj) {
    var data_form = $(obj).parents('form').serialize();

    // console.log(data_form);
    // return false;

    var name = $(obj).parent('form').children('.input_text').children('.r_name').val(),
        email = $(obj).parent('form').children('.input_text').children('.r_email').val(),
        // phone = $(obj).parent('form').children('.input_text').children('.r_phone').val(),
        content = $(obj).parent('form').children('.r_content').val();
    
    if (isNull(name) || isNull(email) || isNull(content)) {
        alert("名称, 邮箱, 留言内容不可为空");
        return false;
    }

    $.post('', data_form, function (data) {
        if (data.code == 2) {
            // console.log(data.data)
            var data = data.data;
            li_html = '<div class="r_content_box">';
            li_html += '<div class="r_content">'
                + '<span class="at j_user_card " username="' + data.name + '">'
                + data.name + '</span>&nbsp;回复:&nbsp;&nbsp; <span class="lzl_content_main">' + data.content
                + '</span></div>';

            li_html += ' <div class="r_reply_botton text-r">'
                + ' <a href="javascript:void(0);" onclick="accusation(this)" data-stat="'+data.id+'"><span>举报</span></a>&nbsp;|&nbsp;&nbsp;'
                + '<span class="lzl_op_list j_lzl_o_l"></span>'
                + '<span class="lzl_time">'+data.time+'</span>'
                + '<a href="#" class="lzl_s_r">&nbsp;|&nbsp;回复</a></div>';

            li_html += '</div>';

            $(obj).parents('.active_replay').before(li_html);
            $(obj).parents('.active_replay').children('.replay_button').css('display', 'block');
            $(obj).parents('.replay_textarea').remove();
        } else {
            alert('添加出错');
            return false;
        }
    }, 'json');
}

/* 收起回复 */
function retract(obj){
    var stat = $(obj).data('stat');

    if (stat == 1) {
        $(obj).parents('.p_content_box').nextAll('.r_content_box').css('display', 'block');
        $(obj).children('span').html("收起回复");
        $(obj).data('stat', 0);
    
        return false;
    }

    $(obj).parents('.p_content_box').nextAll('.r_content_box').css('display', 'none');
    $(obj).children('span').html("展开回复");
    $(obj).data('stat', 1);
}

/* 举报 */
function accusation(obj) {
    id = $(obj).data('stat');

    $.post('complain', {'id': id}, function (data) {
        if (data.code == 2) {
            alert('举报成功, 管理员正在处理');
            return false;
        } else {
            alert('操作失败, 请稍后重试');
            return false;
        }
    }, 'json');
}

// $('.accusation').click(function(){
//     id = $(this).data('stat');

//     $.post('complain', {'id': id}, function (data) {
//         if (data.code == 2) {
//             alert('举报成功, 管理员正在处理');
//             return false;
//         } else {
//             alert('操作失败, 请稍后重试');
//             return false;
//         }
//     }, 'json');
// });